﻿/********************************************************
 * 类名： CodeDAL.cs
 * 功能： 通用生成编号数据层
 *   ver	变更日		作者			变更内容
 * ────────────────────────────────────────
 *   V01.0	2013-12-23	李波			初版
 *
 * Copyright (c) 2013，李波版权所有
 ********************************************************/
using System;
using System.Data;
using System.Text;
using PSS.Utility;

namespace PSS.DAL.CommonManage
{
    public class CodeDAL : DbHelperBase
    {
        /// <summary>
        /// 采购单号
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string GetMaxInitPurFBillNo(string str)
        {
            var strSql = new StringBuilder();
            strSql.Append("select max(DocNumber) maxValue from PSS_InitPur WHERE DocNumber LIKE '%" + str + "%'");
            var maxValue = string.Empty;
            using (var cmd = Db.GetSqlStringCommond(strSql.ToString()))
            {
                try
                {
                    using (IDataReader reader = Db.ExecuteReader(cmd))
                    {
                        if (reader.Read())
                        {
                            maxValue = reader["maxValue"].ToString();
                        }
                    }

                }
                catch (Exception ex)
                {
                    EventsLog.WriteLog("ErrorInfo" + ex.Message);
                }
                return maxValue;
            }
        }

        /// <summary>
        /// 获取最大的收款单号
        /// </summary>
        /// <param name="str"></param>
        public string GetReceiptSingleNo(string str)
        {
            var strSql = new StringBuilder();
            strSql.Append("select max(ReceiptSingleNo) maxValue from PSS_InitReceipt WHERE ReceiptSingleNo LIKE '%" + str + "%'");
            var maxValue = string.Empty;
            using (var cmd = Db.GetSqlStringCommond(strSql.ToString()))
            {
                try
                {
                    using (IDataReader reader = Db.ExecuteReader(cmd))
                    {
                        if (reader.Read())
                        {
                            maxValue = reader["maxValue"].ToString();
                        }
                    }

                }
                catch (Exception ex)
                {
                    EventsLog.WriteLog("ErrorInfo" + ex.Message);
                }
                return maxValue;
            }
        }

        /// <summary>
        /// 获取最大的付款单号
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string GetSinglePaymentNo(string str)
        {
            var strSql = new StringBuilder();
            strSql.Append("select max(SinglePaymentNo) maxValue from PSS_InitPay WHERE SinglePaymentNo LIKE '%" + str + "%'");
            var maxValue = string.Empty;
            using (var cmd = Db.GetSqlStringCommond(strSql.ToString()))
            {
                try
                {
                    using (IDataReader reader = Db.ExecuteReader(cmd))
                    {
                        if (reader.Read())
                        {
                            maxValue = reader["maxValue"].ToString();
                        }
                    }

                }
                catch (Exception ex)
                {
                    EventsLog.WriteLog("ErrorInfo" + ex.Message);
                }
                return maxValue;
            }
        }
    }
}
